package 蓝桥.十五届;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ZhuYi
 * @create 2025/3/26 11:34
 */
public class C分布式队列 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        while (sc.hasNext()) {
            String s = sc.next();
            if (s.equals("add")) {
                a[0]++;
            } else if (s.equals("sync")) {
                int sync = sc.nextInt();
                a[sync] = Math.min(a[sync] + 1, a[0]);
            } else if (s.equals("query")) {
                System.out.println(Arrays.stream(a).min().getAsInt());
            }
        }
    }
}
